package auleiy.halo.client;

import auleiy.halo.ModMain;
import auleiy.halo.items.Items;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.registries.RegistryObject;
import top.theillusivec4.curios.api.client.CuriosRendererRegistry;

import java.util.HashMap;
import java.util.Map;

public class HaloRegistry {

    private static final Map<RegistryObject<Item>, Halo> Halos = new HashMap<>();

    public static void Initialize() { }

    public static void Register(RegistryObject<Item> item, ModelPart model, ResourceLocation tex,
                                float yaw, float roll, Vec3 offset) {
        RenderType rt = RenderType.entityCutoutNoCull(tex, true);
        Halos.put(item, new Halo(model, rt, yaw, roll, offset));
    }

    public static void ClientSetup(FMLClientSetupEvent e) {
        e.enqueueWork(() -> {
            for (Map.Entry<RegistryObject<Item>, Halo> entry : Halos.entrySet())
                CuriosRendererRegistry.register(entry.getKey().get(), () -> new HaloRenderer(entry.getValue()));
        });
    }

    // Offset: X: 右
    //         Y: 上
    //         Z: 前
    //         单位：方块

    static {
        Register(Items.AronaHaloItem, HaloModels.ThickCircleHalo, ModMain.Location("textures/halo/arona.png"),
                15, 30, new Vec3(0.125, 0, 0));
        Register(Items.PlanaHaloItem, HaloModels.ThickCircleHalo, ModMain.Location("textures/halo/plana.png"),
                15, 30, new Vec3(0.125, 0, 0));
    }
}
